package com.lightkits.wms.domain.mainpage;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.lightkits.common.CommonMethodsUtil;
import com.lightkits.common.db.entity.FndOrganizationBase;
import com.lightkits.common.db.entity.FndOrganizationTl;
import com.lightkits.common.db.entity.FndResourceTl;
import com.lightkits.common.db.entity.FndWorker;
import com.lightkits.framework.common.utility.object.ObjectUtil;
import com.lightkits.framework.common.utility.object.ParseUtil;
import com.lightkits.framework.soa.hzero.executor.ServiceExecutor;
import com.lightkits.wms.dto.mainpage.QueryDefaultRequestType;
import com.lightkits.wms.dto.mainpage.QueryDefaultResponseType;
import org.springframework.stereotype.Component;


/**
 * QueryDefaultExecutor
 *
 * @author menxiao.wu@hand-china.com
 * Created on 2019-03-04 20:10
 */
@Component
public class QueryDefaultExecutor implements ServiceExecutor<QueryDefaultRequestType, QueryDefaultResponseType> {


    @Override
    public QueryDefaultResponseType service(QueryDefaultRequestType request) {
        QueryDefaultResponseType response = new QueryDefaultResponseType();
        response.setSuccessful(true);

        com.lightkits.common.model.CurrentWorkerInfo currentWorkerInfo = CommonMethodsUtil.getCurrentWorkerInfo(null);
        Long workerId = currentWorkerInfo.getWorkerId();
        Long organizationId = currentWorkerInfo.getDefaultOrganizationId();

        FndWorker workers = new FndWorker().selectById(workerId);
        FndResourceTl resourceTl = new FndResourceTl().selectOne(new EntityWrapper().eq(FndResourceTl.RESOURCE_ID,workerId));

        FndOrganizationBase organizationBase = new FndOrganizationBase().selectOne(new EntityWrapper().eq(FndOrganizationBase.ORGANIZATION_ID,organizationId));
        FndOrganizationTl organizationTl = new FndOrganizationTl().selectOne(new EntityWrapper().eq(FndOrganizationTl.ORGANIZATION_ID,organizationId));

        response.setWorkerId(ObjectUtil.toString(workerId));
        if (!ObjectUtil.isEmpty(resourceTl) && !ObjectUtil.isEmpty(workers)) {
            response.setWorkerNumber(workers.getWorkerNumber());
            response.setWorker(resourceTl.getResourceName());
        }
        response.setOrganizationId(ObjectUtil.toString(organizationId));
        if (!ObjectUtil.isEmpty(organizationTl) && !ObjectUtil.isEmpty(organizationBase)) {
            response.setOrganizationDescription(organizationTl.getDescription());
            response.setOrganizationCode(organizationBase.getOrganizationCode());
        }
        return response;
    }
}
